function CheckNumKey(){
	if(event.keyCode == 13) return true;
	//下注金額必須為數值
	if((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode > 95 || event.keyCode < 106)){
		alert(notNumber);
		return false;
	}
}

function OtherCheck(strGold){
	//請填入下注金額！
	if(strGold == ""){
		alert(noMoney);
		return false;
	}
	//下注金額必須為數值
	if(isNaN(strGold) == true){
		alert(notNumber);
		return false;
	}
	//不能低於最低下注金額
	if(eval(strGold) < chkMinStake){
		alert(underMinStake+chkMinStake.toString());
		return false;
	}
	//不能超過本期單注限額
	if(eval(strGold) > chkLottoMaxBetLimitValue){
		alert(overLottoMaxBetLimitValue+chkLottoMaxBetLimitValue);
		return false;
	}
	//不能超過單注限額
	if(eval(strGold) > chkMaxBetLimitValue){
		alert(overBetLimit + chkMaxBetLimitValue);
		return false;
	}
}

function CheckOK(){
	var objGold = document.CommonWagerForm.StakeMoney;
	if (OtherCheck(objGold.value) == false){
		objGold.focus();
		return;
	}
	var intNum = 0;
	var arrNum = SeleteBall().split(",");
	var objGold = document.CommonWagerForm.StakeMoney;
	var ArrGame = eval("parent.Game"+isSpecial);
	//請選擇下注球號
	if (arrNum == "") {
		alert(noBall);
		return;
	}

	for (var i = 0 ; i < (arrNum.length - 1); i++){
		//alert(arrNum.length+":"+i);
		intNum = eval(arrNum[i]);
		if (WagerAdd(arrNum[i], ArrGame[intNum][4], ArrGame[intNum][5], ArrGame[intNum][6], objGold.value) == false){
			//alert("QQ");
			return;
		}
	}
	
	SelectColorBall("cancel");
	objGold.value = "";
}

function WagerSUM() {
	var strWager = "", arrWList = new Array(), intTotal=0, i = 0;                
	var objWList = document.CommonWagerForm.WagerList;

	//請先下注
	if (objWList.length==0)	{
		alert(noWager);
		return false;
	}
		
	for(i = 0; i < objWList.length; i++)	{
		strWager += objWList.options[i].value+"@";
		arrWList = objWList.options[i].value.split("#");
		intTotal += eval(arrWList[2]);
	}
	//總金額不能超過信用餘額
	if (intTotal > chkCredit) {
		alert(overCredit+chkCredit);
		return false;
	}
	//確定下注？
	if (!confirm(sureStake))	return false;  
	document.CommonWagerForm.WagerContent.value = strWager;
}

function SeleteBall(){
	var i = 0, strNumbers = "", strNum = "", objNum;

	for (i=1; i <= 21; i++){
		strNum = NumFormat(i);
		objNum = document.getElementById("OddsTip"+strNum);

		if(objNum.className == "left_snq_wagertable_click"){
			strNumbers += strNum+",";
		}
	}
	
	return strNumbers;
}

function SelectColorBall(strColor){
	var i = 0, c = 0, strNum = "", objNum;
	switch(strColor) {
		case "cancel":
			c = 4;
			break;
		case "all":
			c = 5;
			break;
		default:
			return;
			break;
	}
	
	for(i = 1; i < 22 ; i++){
		strNum = NumFormat(i);
		objNum = document.getElementById("OddsTip"+strNum);
		if (c == 4){
			objNum.className = "left_snq_wagertable";
			continue;
		}
		
		if (c==5){
			if(objNum.className == "left_snq_wagertable_click"){
				objNum.className = "left_snq_wagertable";
			}else{
				objNum.className = "left_snq_wagertable_click";
			}
		}
	}
}

function SelectOENum(intOE){
	var i = 0, strNum = "", objNum;
	if(intOE != 1 && intOE != 0)return;
	
	for(i = 1; i < 22 ; i++){
		if (i % 2 == intOE)	{
			strNum = NumFormat(i);
			objNum = document.getElementById("OddsTip"+strNum);
			if(objNum.className == "left_snq_wagertable_click"){
				objNum.className = "left_snq_wagertable";
			}else{
				objNum.className = "left_snq_wagertable_click";
			}
		}
	}
}

function SelectOUNum(intOU){
	var i = 0, strNum = "", objNum, MaxNum = 0, MinNum = 0;
	if(intOU != 1 && intOU != 0)return;
	if(intOU == 1){
		MaxNum = 22;
		MinNum = parseInt(SpecialOverNumber);
	}else{
		MaxNum = parseInt(SpecialOverNumber);
		MinNum = 1;
	}
	for(i = MinNum; i < MaxNum ; i++){
		if(i >= parseInt(DrawSpecial))continue;
		strNum = NumFormat(i);
		objNum = document.getElementById("OddsTip"+strNum);
		if(objNum.className == "left_snq_wagertable_click"){
			objNum.className = "left_snq_wagertable";
		}else{
			objNum.className = "left_snq_wagertable_click";
		}
	}
}

function SelectSumNum(intOE){
	var i = 0, strNum = "", objNum;
	var intLNum = 0, intRNum = 0, intSum = 0;

	if(intOE != 1 && intOE != 0)return;
	
	for(i = 1; i < 22 ; i++){
	    strNum = NumFormat(i);
	    intLNum = parseInt(strNum.substr(0,1));
	    intRNum = parseInt(strNum.substr(1,1));
	    intSum = intLNum + intRNum;
	    if (intSum % 2 == intOE){
			objNum = document.getElementById("OddsTip"+strNum);
			if(objNum.className == "left_snq_wagertable_click"){
				objNum.className = "left_snq_wagertable";
			}else{
				objNum.className = "left_snq_wagertable_click";
			}
		}
	}
}


function NumFormat(intNum){
	return (intNum < 10)?("0" + intNum.toString()):intNum.toString();
}

function GetNumber(objO, strNum, strMType){
	var objFrm = document.CommonWagerForm;
	var objNum = document.getElementById("OddsTip"+strNum);
	if(strMType == "click"){
		if(objNum.className == "left_snq_wagertable_click"){
			objNum.className = "left_snq_wagertable_over";
		}else{
			objNum.className = "left_snq_wagertable_click";
		}
	}else if(strMType == "over"){
		if(objNum.className == "left_snq_wagertable")objNum.className = "left_snq_wagertable_over";
	}else{
		if(objNum.className == "left_snq_wagertable_over")objNum.className = "left_snq_wagertable";
	}
}

function GetWagerTable(){
	var objWTable = document.getElementById("wager_table"), i = 0, j = 0, intNum = 0, strNum = "";
	var ArrGame = eval("parent.Game"+isSpecial);
	document.CommonWagerForm.GambleID.value = ArrGame[1][1];

	with(objWTable)	{
		while(rows.length > 1)	deleteRow(rows.length - 1);
			
		for(i =1; i <= 5; i++)	{
			newTR = insertRow(rows.length);
			newTR.className = "left_snq_wagertable";
			with(newTR){
				var intCellNo = 0;
				for (j = 0; j <= 4; j++){
					intNum = 5*j + i;
					strNum = NumFormat(intNum);
										
					newTD = insertCell(j);
					newTD.className = "left_snq_wagertable";
					if (intNum > 21) {
						newTD.innerHTML = "&nbsp;";
					}else{
						newTD.id = "OddsTip" + strNum;
						newTD.width = "39px";
						newTD.height = "19px";
						if (ArrGame[intNum][6] == "1") {
							newTD.innerHTML = "&nbsp;";
						}else{
							newTD.innerHTML = "<span  style=\"cursor: hand;\" onmousedown=\"GetNumber(this,'"+strNum+"','click')\" onmouseover=\"GetNumber(this,'"+strNum+"','over')\" onmouseout=\"GetNumber(this,'"+strNum+"','out')\" class=\"number_color_green\">"+strNum+"</span>";
						}
					}
				}
			}
		}
	}
}

function ClearWagerData(){
	with(document.CommonWagerForm){
		var i = 0;
		for (i = 0; i < WagerList.length; i++) {
			WagerList.remove(i);
			i--;
		}
	}
}

function WagerAdd(strNum, strOID, strOdds, strStop, strGold){
	switch(isSpecial){
		case "1":
			var strWType = WType_SpA;
			break;

		case "5":
		case "6":
		case "7":
		case "8":
			var strWType = WType_NSB.replace("1", (parseInt(isSpecial) - 4).toString());
			break;

		default:
			alert("^_^");
			return false;
			break;
	}
	//號球已經封牌！
	if (strStop == "1") {
		alert(strNum + stopBall);
		return false;
	}
	var strWOption = strWType + " " + strNum + "@" + strOdds + " $" + strGold;
	var strWValue = strNum + "#" + strOID + "#" + strGold + "#" + isSpecial;
	with(document.CommonWagerForm){
		for (var i = 0; i < WagerList.length; i++) {
			var arrT = WagerList.options[i].value.split("#");
			if(eval(arrT[0]) == eval(strNum)){
				alert(AlertNumberDouble);
				ClearWagerData();
				return false;
			}
		}
	}
	var oOption = document.createElement("OPTION");
	//document.CommonWagerForm.WagerList.add(oOption);
	document.getElementById("WagerList").options.add(oOption);
	oOption.innerText = strWOption;
	oOption.text = strWOption;
	oOption.value = strWValue;
	//var oOption = new Option(strWOption, strWValue);
}

function FinalCheck(){
	with(document.CommonWagerForm){
		CancelBTN.disabled = true;
		SubmitBTN.disabled = true;
		ClearBTN.disabled = true;
		
		if (WagerSUM() == false) {
			CancelBTN.disabled = false;
			SubmitBTN.disabled = false;
			ClearBTN.disabled = false;
			return;
		}

		if (WagerContent.value != "") {
			submit();
		}else{
			CancelBTN.disabled = false;
			SubmitBTN.disabled = false;
			ClearBTN.disabled = false;
			return;
		}
	}
}